package com.xywy.tangandroid.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xywy.tangandroid.R;
import com.xywy.tangandroid.activity.LoginAct;
import com.xywy.tangandroid.activity.MssageBoxAct;
import com.xywy.tangandroid.activity.MyCollectionAct;
import com.xywy.tangandroid.activity.PersonDataAct;
import com.xywy.tangandroid.activity.SettingAct;
import com.xywy.tangandroid.vollery.VolleyManager;

public class PersonFragement extends Fragment implements OnClickListener {

	public static Context context;
	private RelativeLayout left_img;
	private TextView middle_title;
	private TextView right_title;
	private View tobar;
	private ImageView right_img;
	private View view;
	private RelativeLayout person_data_relat;
	private RelativeLayout message_box_relat;
	private RelativeLayout my_like;
	private RelativeLayout setting_relat;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.fragement_person, null);

		return view;

	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		initView(view);
		initonclick();
	}

	private void initView(View view) {

		left_img = (RelativeLayout) view.findViewById(R.id.left_img);
		middle_title = (TextView) view.findViewById(R.id.middle_title);
		right_title = (TextView) view.findViewById(R.id.right_title);
		right_img = (ImageView) view.findViewById(R.id.right_img);

		person_data_relat = (RelativeLayout) view
				.findViewById(R.id.person_data_relat);
		message_box_relat = (RelativeLayout) view
				.findViewById(R.id.message_box_relat);
		my_like = (RelativeLayout) view.findViewById(R.id.my_like);
		setting_relat = (RelativeLayout) view.findViewById(R.id.setting_relat);

		left_img.setVisibility(View.INVISIBLE);
		middle_title.setText(getResources().getString(R.string.persion));
		right_title.setVisibility(View.VISIBLE);
		SharedPreferences sp = getActivity().getSharedPreferences(
				"xywy_tang_user", Context.MODE_PRIVATE);
		
		right_title.setText(sp.getString("accountstr",""));

	}

	private void initonclick() {

		left_img.setOnClickListener(this);
		middle_title.setOnClickListener(this);
		right_img.setOnClickListener(this);

		person_data_relat.setOnClickListener(this);
		message_box_relat.setOnClickListener(this);
		my_like.setOnClickListener(this);
		setting_relat.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.person_data_relat:
			Intent intent1 = new Intent(getActivity(), PersonDataAct.class);
			startActivity(intent1);

			break;
		case R.id.message_box_relat:
			Intent intent4 = new Intent(getActivity(), MssageBoxAct.class);
			startActivity(intent4);

			break;
		case R.id.my_like:
			Intent intent2 = new Intent(getActivity(), MyCollectionAct.class);
			startActivity(intent2);

			break;
		case R.id.setting_relat:
			Intent intent3 = new Intent(getActivity(), SettingAct.class);
			startActivity(intent3);
			break;

		default:
			break;
		}

	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		VolleyManager.cancelRequest(getActivity());
	}

}
